package Demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-03-05
 * Time: 13:34
 */
class Animal {
    public void eat() {
        System.out.println("吃饭");
    }
}

class Dog extends Animal {
    @Override
    public void eat() {
        System.out.println("吃狗粮");
    }
}

class Cat extends Animal {
    @Override
    public void eat() {
        System.out.println("吃猫粮");
    }
}

public class Test1 {
    public static void eat(Animal animal) {
        animal.eat();
    }

    public static void main(String[] args) {
        Dog dog = new Dog();
        Cat cat = new Cat();
        eat(dog);
        eat(cat);
    }

    public static void main1(String[] args) {
        Animal animal = new Dog();
        Dog dog = new Dog();
        if (animal instanceof Dog) {
            dog = (Dog) animal;
        }
    }

    public static void main2(String[] args) {
        Dog dog = new Dog();
        Animal animal = new Animal();
        if (animal instanceof Dog)
            dog = (Dog) animal;

    }

//    public static void main2(String[] args) {
//        Animal animal1 = new Dog();
//    }

}
